//
//  SYWanChengTableViewCell.m
//  SanYiTeaching
//
//  Created by 郑浩然 on 2019/4/20.
//  Copyright © 2019年 SanYi. All rights reserved.
//

#import "SYWanChengTableViewCell.h"

@interface SYWanChengTableViewCell ()
@property (strong, nonatomic) UIView *jinXingView;//进行中
@property (strong, nonatomic) UIView *wanchengView;//已完成
@property (strong, nonatomic) UIButton *checkButton;//查看
@property (strong, nonatomic) UIButton *deleteBtn;//删除
@property (strong, nonatomic) UIButton *chakanBtn;//查看
@property (strong, nonatomic) UIView *bgView;//背景
@property (strong, nonatomic) UIView *bgtwoView;//第二层view

@end

@implementation SYWanChengTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self initSubView];
    }
    return self;
}

- (void)initSubView {
    [self addSubview:self.bgView];
    [self.bgView addSubview:self.bgtwoView];
    
    [self.bgtwoView addSubview:self.jinXingView];
    [self.bgtwoView addSubview:self.wanchengView];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self);
        make.left.equalTo(self.mas_left).offset(14);
        make.right.equalTo(self.mas_right).offset(-14);
    }];
    [self.bgtwoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self);
        make.left.equalTo(self.bgView.mas_left).offset(14);
        make.right.equalTo(self.bgView.mas_right).offset(-14);
    }];
    CGFloat jianju = 14;
    [self.jinXingView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self);
        make.left.equalTo(self.bgtwoView.mas_left).offset(jianju);
        make.right.equalTo(self.bgtwoView.mas_right).offset(-jianju);
    }];
    [self.wanchengView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.bgView);
        make.left.equalTo(self.bgtwoView.mas_left).offset(jianju);
        make.right.equalTo(self.bgtwoView.mas_right).offset(-jianju);
    }];
    
    NSArray *xiaoArr = @[@"123456",@"关晓彤",@"女",@"13000000000",@"2019-01-30",@"听课",@"查看",@"移出"];
    CGFloat whit = (865*fw)/8;
    
    UILabel *contLab = nil;//公公lab
    for (NSInteger i = 0; i < 8; i++) {
        if (i == 6) {//查看
            _checkButton = [UIButton buttonWithType:UIButtonTypeCustom];
            [_checkButton setImage:[UIImage imageNamed:@"sx_xiaozu_chakan"] forState:UIControlStateNormal];
            _checkButton.titleLabel.font = [UIFont systemFontOfSize:12];
            [_checkButton addTarget:self action:@selector(lookUp) forControlEvents:UIControlEventTouchUpInside];
            _checkButton.tag = 20+i;
            [self.jinXingView addSubview:_checkButton];
            [_checkButton mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(contLab.mas_right);
                make.top.equalTo(self.jinXingView.mas_top);
                make.width.equalTo(self.jinXingView).multipliedBy(0.125);
                make.height.mas_equalTo(40);
            }];
        } else if (i == 7) {//移出
            _deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            
            [_deleteBtn setImage:[UIImage imageNamed:@"sx_xiaozu_yichu"] forState:UIControlStateNormal];
            _deleteBtn.titleLabel.font = [UIFont systemFontOfSize:12];
            [_deleteBtn addTarget:self action:@selector(deleteBtnClick) forControlEvents:UIControlEventTouchUpInside];
            _deleteBtn.tag = 20+i;
            [self.jinXingView addSubview:_deleteBtn];
            [_deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.checkButton.mas_right);
                make.top.equalTo(self.jinXingView.mas_top);
                make.width.equalTo(self.jinXingView).multipliedBy(0.125);
                make.height.mas_equalTo(40);
            }];
        } else {
            UILabel *title = [UILabel titleColour:TITLECOLOR
                                       titleFount:14
                                         pingfang:@"PingFang-SC-Medium"
                                        alignment:NSTextAlignmentCenter
                                        titleLine:1];
            if (i == 5) {
                title.textColor = [UIColor colorWithHexString:@"#FF4800"];
            }
            title.tag = i;
            title.text = xiaoArr[i];
            [self.jinXingView addSubview:title];
            if (i == 0) {
                contLab = title;
                [title mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(self.jinXingView.mas_left);
                    make.top.equalTo(self.jinXingView.mas_top);
                    make.width.equalTo(self.jinXingView).multipliedBy(0.125);
                    make.height.mas_equalTo(40);
                }];
            } else {
                [title mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(contLab.mas_right);
                    make.top.equalTo(self.jinXingView.mas_top);
                    make.width.equalTo(self.jinXingView).multipliedBy(0.125);
                    make.height.mas_equalTo(40);
                }];
                contLab = title;
            }
        }
    }
   // NSArray *wanArr = @[@"工号",@"姓名",@"性别",@"手机号",@"加入日期",@"最近状态",@"查看"];
    
    UILabel *contLab1 = nil;
    for (NSInteger i = 0; i < 7; i++) {
        
        if (i == 6) {//查看
            _chakanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            [_chakanBtn setImage:[UIImage imageNamed:@"sx_xiaozu_chakan"] forState:UIControlStateNormal];
            [_chakanBtn addTarget:self action:@selector(lookUp) forControlEvents:UIControlEventTouchUpInside];
            _chakanBtn.tag = 40+i;
            [self.wanchengView addSubview:_chakanBtn];
            [_chakanBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(contLab1.mas_right);
                make.top.equalTo(self.jinXingView.mas_top);
                make.width.equalTo(self.jinXingView).multipliedBy(0.143);
                make.height.mas_equalTo(40);
            }];
        } else {
            UILabel *title = [UILabel titleColour:TITLECOLOR
                                       titleFount:14
                                         pingfang:@"PingFang-SC-Medium"
                                        alignment:NSTextAlignmentCenter
                                        titleLine:1];
            title.tag = 40+i;
            if (i == 5) {
                title.textColor = [UIColor colorWithHexString:@"#FF4800"];
            }
            title.text = xiaoArr[i];
            [self.wanchengView addSubview:title];
            if (i == 0) {
                contLab1 = title;
                [title mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(self.jinXingView.mas_left);
                    make.top.equalTo(self.jinXingView.mas_top);
                    make.width.equalTo(self.jinXingView).multipliedBy(0.143);
                    make.height.mas_equalTo(40);
                }];
            } else {
                [title mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(contLab1.mas_right);
                    make.top.equalTo(self.jinXingView.mas_top);
                    make.width.equalTo(self.jinXingView).multipliedBy(0.143);
                    make.height.mas_equalTo(40);
                }];
                contLab1 = title;
            }
        }
    }
}

- (void)incomingDataInteger:(NSInteger)index backColor:(UIColor *)color {
    if (index == 0) {
        self.jinXingView.hidden = NO;
        self.wanchengView.hidden = YES;
        self.bgtwoView.backgroundColor = color;
    } else {
        self.jinXingView.hidden = YES;
        self.wanchengView.hidden = NO;
        self.bgtwoView.backgroundColor = color;
    }
}


//查看
- (void)lookUp {
    if ([self.delegate respondsToSelector:@selector(selectTableViewCellType:)]) {
        [self.delegate selectTableViewCellType:SYWanChengTableViewCellTypeChaKan];//查看
    }
}
//移出
- (void)deleteBtnClick {
    if ([self.delegate respondsToSelector:@selector(selectTableViewCellType:)]) {
        [self.delegate selectTableViewCellType:SYWanChengTableViewCellTypeDelete];//查看
    }
}

- (UIView *)jinXingView {
    if (!_jinXingView) {
        _jinXingView = [[UIView alloc] init];
//        _jinXingView.backgroundColor = [UIColor redColor];
    }
    return _jinXingView;
}

- (UIView *)wanchengView {
    if (!_wanchengView) {
        _wanchengView = [[UIView alloc] init];
//        _wanchengView.backgroundColor = [UIColor whiteColor];
    }
    return _wanchengView;
}

- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = [UIColor colorWithHexString:@"F8F8F8"];
    }
    return _bgView;
}
//第二层view
- (UIView *)bgtwoView {
    if (!_bgtwoView) {
        _bgtwoView = [[UIView alloc] init];
    }
    return _bgtwoView;
}

@end
